﻿@using KRM.Core
@model IEnumerable<KRM.Core.vOrderView_OrderItems>
@{ 
    tblOrder order = ViewBag.Order;
    KRMEntities db = ViewBag.db;
    var orderInRefundRequest = db.tblKRMRefundRequests.Count(a => a.OrderID == order.OrderID) > 0;
    tblUser user = ViewBag.User;
}
<script>
    function GetOrderInRefundRequest() {
        var orderInRefundRequest = @orderInRefundRequest.ToString().ToLower();
        if (orderInRefundRequest) {
            if (confirm("This Order has confirmed the Refund request. Do you want to confirm the Refund request again?")) {
                PopupCenter('/orderview/addrefundrequest?orderid=@order.OrderID', 1100, 670);
            }
        } else {
            PopupCenter('/orderview/addrefundrequest?orderid=@order.OrderID', 1100, 670);
        }
    }
    function reasonemailchange(reasonid) {
        App.blockUI($("#fr-RemoveLoadItem"));
        if (reasonid == 12) {
            $(".deliverydate").show();
        } else {
            $(".deliverydate").hide();
        }
        $.ajax({            
            url: "/load/reasonemailchange?reasonid=" + reasonid,
            success:function(data) {
                $(".email-content").html(data);
                App.unblockUI($("#fr-RemoveLoadItem"));
            }
        });
    }
</script>
<div class="order-items-scroll">
    <table class="table table-bordered table-fix tbl-orderitemdetail" data-height="200">
        <thead>
            <tr>
                <th></th>
                <th>Action</th>
                <th>Status</th>
                <th>Quantity</th>
                <th>ProductName</th>
                <th>ProductOption</th>
                <th>SubOptions</th>
                <th>ProductCode</th>
                <th>ItemPrice</th>
                <th>Supplier</th>
                <th>DeliveryDays</th>
                <th>DespatchDate</th>
                <th>Cancelled</th>
                <th>LastSupplierConfirmation</th>
                <th>ItemStatus</th>

            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                //var isDD = db.spProductOptionIsDirectDispatch(item.ProductOptionID).FirstOrDefault();
                <tr style="cursor: pointer" onclick="loaditemorderparts(@item.OrderItemID,@item.OrderID,$(this).hasClass( 'row-selected'))">
                    <td>@Html.Partial("Partial/OrderView/ajax/_OrderItemDetails", item)</td>
                    <td style="max-width: none; overflow: visible;">
                        <div class="btn-group">
                            <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><span class="caret"></span></a>
                            <ul class="dropdown-menu dropdowm-right">
                                @if (user.HasPermission(Permissions.CanRemoveItemFromLoadOnOrderview))
                                {
                                    <li><a href="javascript:;" onclick="removeloaditemonorderview(@item.OrderItemID)">Remove Item From Load</a></li>
                                }
@*@if (isDD != null && isDD.carrierID != 3)
                                {*@
                                <li>
                                    <a href="javascript:;" onclick="createrdmfromitem(@item.OrderItemID,@item.OrderID)">Create RDM
                                    </a>
                                </li>
                                @*}*@
                                <li>
                                    <a href="javascript:;" onclick="PopupCenter('/orderview/viewauditforaddingpart/@item.OrderItemID?orderref=@order.OrderRef', 500, 500)">View Audit For Adding Part</a>
                                </li>
                                <li>
                                    <a href="javascript:;" onclick="PopupCenter('/orderview/orderitemphoto/@item.OrderItemID?orderref=@order.OrderRef', 900, 600)">Add photos</a>
                                </li>
                            </ul>
                        </div>
                    </td>
                    <td>@item.Status</td>
                    <td>@item.Quantity</td>
                    <td>@item.Product_Name</td>
                    <td>@item.Product_Option</td>
                    <td>@item.Sub_options</td>
                    <td>@item.ProductCode</td>
                    <td>@item.Item_Price</td>
                    <td>@item.Supplier</td>
                    <td>@item.deliveryDays</td>
                    <td>@item.DespatchDate</td>
                    <td>@item.Cancelled</td>
                    <td>@item.LastSupplierConfirmation</td>
                    <td>@item.ItemStatus</td>

                </tr>
            }
        </tbody>
    </table>
</div>
<div class="row-fluid action-orderitem">
    <div class="span4" style="padding-top: 17px">
        <div class="span2">
        </div>
        <div class="span10">
            <div class="row-fluid">
                <div class="span6">
                    Est Despatch Date:
                </div>
                <div class="span6"></div>
            </div>
            <div class="row-fluid">
                <div class="span6">
                    Est Delivery Date:
                </div>
                <div class="span6"></div>
            </div>
            <div class="row-fluid">
                <div class="span6">
                    Drivers Telephone Number:
                </div>
                <div class="span6"></div>
            </div>
        </div>
    </div>
    <div class="span2">
        <div class="row-fluid"></div>
        <div class="row-fluid">
        </div>
        <div class="row-fluid">
            <a href="javascript:;" onclick="PopupCenter('/orderview/viewpickhistory?orderid=@order.OrderID',900,650)" class="btn btn-orderitem btn-info">View Pick History</a>
        </div>
    </div>
    <div class="span6">
        <div class="row-fluid" style="margin-top: 10px">
            <a href="javascript:;" onclick="javascript: alert('Please choose a OrderItem!');" class="btn span4 btn-info">Change Date</a>
            <a href="javascript:;" onclick="javascript: alert('Please choose a OrderItem!');" class="btn span4 btn-info">Audit Picking A Day</a>
            <a href="javascript:;" onclick="CheckCancelOrder(@order.OrderID)" class="btn btn-danger span4">Cancel Order</a>
        </div>
        <div class="row-fluid" style="margin-top: 10px; margin-bottom: 10px">
            <a href="javascript:;" onclick="javascript: alert('Please choose a OrderItem!');" class="btn span4 btn-info">Override Change Date</a>
            <a href="javascript:;" onclick="javascript: alert('Please choose a OrderItem!');" class="btn span4 btn-info">View Sub Options</a>
            <a href="javascript:;" onclick="javascript: alert('Please choose a OrderItem!');" class="btn btn-danger span4">Cancel Item</a>
        </div>
        <div class="row-fluid">
            <a href="javascript:;" onclick="@(user.HasPermission(Permissions.CanChangeVipStatus) ? "PopupCenter('/orderview/assignvipstatus?orderid=" + order.OrderID + "',500,300)" : "javascript:alert(\"You don't have permission to change vip status!\");")" class="btn span4 btn-info" style="color: red; font-weight: bold">@ViewBag.VipStatus</a>
            <a class="btn span4 btn-info" onclick="checkorderisinparagon('@order.OrderRef')">Check Order Paragon</a>
            @if (user.HasPermission(Permissions.SendRefundRequest))
            {
                <a href="javascript:;" onclick="GetOrderInRefundRequest()" class="btn btn-info span4">Add Refund Request</a>
            }
        </div>
    </div>
    @*<div class="span2" style="margin-left: 2px">
    </div>*@
    <div id="ModalSendRemoveOrderFromLoadEmail" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>

</div>
<div id="ChooseReason" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="ChooseReason" aria-hidden="true">
    <form action="/load/RemoveLoadItem" class="margin0" id="fr-RemoveLoadItem" method="POST">
        <input type="hidden" name="orderitemid" id="hf-orderitemid" />
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
            <h5>Choose Reason</h5>
        </div>
        <div class="modal-body">
            <div class="row-fluid">
                <div class="span3">Reason</div>
                <div class="span6">
                    @Html.DropDownList("ReasonID", null, "---Please choose---", new { @class = "input-block-level", onchange = "reasonemailchange(this.value)", required = "required" })
                </div>
            </div>
            <div class="row-fluid deliverydate" style="display: none">
                <div class="span3">Delivery Date</div>
                <div class="span6">
                    <div class="input-append datetimepicker">
                        <input data-format="dd/MM/yyyy" type="text" name="deliverydate" value="@string.Format("{0:dd/MM/yyyy}", DateTime.Now)">
                        <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                        </span>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <p>Email content</p>
                <div class="email-content"></div>
            </div>
        </div>
        <div class="modal-footer">
            <button class="btn btn-primary w100" type="submit">Send</button>
            <button class="btn w100" data-dismiss="modal" aria-hidden="true">Cancel</button>
        </div>
    </form>
</div>
